package com.haust.leyou.mapper;

import com.haust.leyou.pojo.Brand;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @Auther: csp1999
 * @Date: 2020/12/08/19:52
 * @Description:
 */
@Repository
public interface BrandMapper extends Mapper<Brand> {

    /**
     * 向品牌分类中间表中插入品牌id和分类id
     *
     * @param cid 商品分类id
     * @param bid 品牌id
     */
    @Insert("INSERT INTO tb_category_brand (category_id, brand_id) VALUES (#{cid},#{bid})")
    int insertBrandAndCategory(@Param("cid") Long cid, @Param("bid") Long bid);

    /**
     * 根据cid 查询品牌集合
     *
     * @param cid
     * @return
     */
    @Select("SELECT * FROM tb_brand a INNER JOIN tb_category_brand b ON a.id=b.brand_id WHERE b.category_id=#{cid}")
    List<Brand> selectBrandsByCid(@Param("cid") Long cid);
}
